/**
 * 
 */
package com.sms.businessservice.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.sms.business.User;
import com.sms.businessservice.UserBusinessService;
import com.sms.dataservice.UserDataService;
import com.sms.vo.UserVO;

/**
 * @author Sahdev Kamboj
 *
 */
public class UserBusinessServiceImpl implements UserBusinessService{
	
	
	private UserDataService userDataService;
	
	

	public void setUserDataService(UserDataService userDataService) {
		this.userDataService = userDataService;
	}

	@Override
	public void saveUser(UserVO userVO) throws Exception {
		User user = new User();
		user.setUserName(userVO.getUserName());
		user.setUserPassword(userVO.getUserPassword());
		userDataService.saveUser(user);
		
	}

	@Override
	public List<UserVO> fetchAllUser() {
		User user = null;
		List<User> userList = new ArrayList<User>();
		List<UserVO>  userVOLinkedList = new LinkedList<UserVO>();
		userList = userDataService.getUsers();
		
		Iterator<User> iterator = userList.iterator();
		while (iterator.hasNext()) {
			user = iterator.next();
			UserVO userVO = new UserVO();
			BeanUtils.copyProperties(user, userVO);
			userVOLinkedList.add(userVO);
		}
		return userVOLinkedList;
	}

}
